/*************************************************
Author: will
Date: 10/17/2012
Description:
Notes: 
*************************************************/

#ifndef __CItemConfig_h__
#define __CItemConfig_h__

#include "CTHashObjectMgr.h"
#include "commclass.h"

class CItemConfigData
{
public:
	CItemConfigData() 
    {
        _ucItemType = 0;
        _shMaxCountPerGrid = 0;
        _iPosValue = 0;
        _iUseGrid = 0;
        _ucOperFlag = 0;
        _bCanFillInGroundBag = false;
	}

public:
	unsigned char _ucItemType;           // 物品类型(取值范围ITEM_TYPE),
    
    int             _shMaxCountPerGrid;   // 同一格子最大堆叠数
    int            _iPosValue;           // 排序权值.

    int            _iUseGrid;            // 物品占用格子数
    unsigned char  _ucOperFlag;           // 是否可丢弃, 是否贵重物品, 是否可出售

    bool           _bCanFillInGroundBag; //能否放入地上背包
};

class CItemConfig
{
public:
	CItemConfig() 
    {
        _astItemConfig.m_iUsedCount = ITEM_TYPE_MAX;
	}

    static bool IsValidItemType (unsigned char ucItemType)
    {
        if (ucItemType < ITEM_TYPE_MIN || ucItemType > ITEM_TYPE_MAX)
        {
            return false;
        }

        return true;
    }

    int AddConfig(CItemConfigData& stConfigData);
    int GetConfig(unsigned char ucItemType, CItemConfigData& stConfigData);
private:
     CTArray<CItemConfigData, ITEM_TYPE_MAX> _astItemConfig;
};

class CFruitUnitConfig
{
public:
    CFruitUnitConfig ()
    {
        _bHasConfig = false;
        _ucItemType = 0;
        _usFruitId = 0;
        _ucLevel = 0;
        _ucStar = 0;
        _iRecoverGoldCost = 0;
        _iSellSilver = 0;
    }

    bool _bHasConfig;
    unsigned char _ucItemType;           // 物品类型(取值范围ITEM_TYPE)
    unsigned short _usFruitId;           // 果实ID
    unsigned char  _ucLevel;             // 果实等阶
    unsigned char  _ucStar;              // 果实星级
    int  _iRecoverGoldCost;              // 恢复有效期所需金币
    int _iSellSilver;
};

class CFruitConfig
{
public:
    CFruitConfig() 
    {
        _stCfg.Clear();
    }

    int AddConfig(CFruitUnitConfig& stConfigData)
    {
        if (stConfigData._usFruitId > MAX_FRUIT_CONFIG_NUM)
        {
            CT_ERROR(("add fruit config error, id %d", stConfigData._usFruitId));
            return ERROR_PET_FRUIT_CONFIG;
        }

        if (_stCfg[stConfigData._usFruitId]._bHasConfig)
        {
            CT_ERROR(("add duplicated fruit config error, id %d", stConfigData._usFruitId));
            return ERROR_PET_FRUIT_CONFIG;
        }

        _stCfg[stConfigData._usFruitId] = stConfigData;
        _stCfg[stConfigData._usFruitId]._bHasConfig = true;

        return 0;
    }

    bool IsFruitValid(unsigned short usFruitId)
    {
        if (0 == usFruitId || usFruitId > MAX_FRUIT_CONFIG_NUM)
        {
            CT_ERROR(("fruit config error, id %d", usFruitId));
            return false;
        }

        if (!_stCfg[usFruitId]._bHasConfig)
        {
            CT_ERROR(("fruit config error, id %d", usFruitId));
            return false;
        }

        return true;
    }

    int GetFruitConfig(unsigned short usFruitId, CFruitUnitConfig& stConfigData)
    {
        if (!IsFruitValid(usFruitId))
        {
            return ERROR_PET_FRUIT_NONE;
        }

        stConfigData = _stCfg[usFruitId];
        return 0;
    }

    CTArray<CFruitUnitConfig, MAX_FRUIT_CONFIG_NUM>  _stCfg;
};


#endif // __CItemConfig_h__

